/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ik;

import ik.solver.Joint2d;

/**
 *
 * @author Vitaljok
 */
public class JointPanel extends javax.swing.JPanel {

    private Joint2d joint;

    public Joint2d getJoint() {
        return joint;
    }

    public void setJoint(Joint2d joint) {
        this.joint = joint;
        this.firePropertyChange("jointLenght", 0f, this.joint.getLenght().floatValue());
        this.firePropertyChange("jointAlfa", 0f, this.joint.getAlfa().floatValue());
    }

    public int getJointLenght() {
        if (this.joint != null) {
            return (int) Math.round(this.joint.getLenght() * 10);
        } else {
            return 0;
        }
    }

    public void setJointLenght(int value) {
        if (this.joint != null) {
            this.joint.setLenght(value / 10d);
        }
    }
    
    public int getJointAlfa() {
        if (this.joint != null) {
            return (int) Math.round(this.joint.getAlfa());
        } else {
            return 0;
        }
    }

    public void setJointAlfa(int value) {
        if (this.joint != null) {
            this.joint.setAlfa((double)value);
        }
    }

    /**
     * Creates new form JointPanel
     */
    public JointPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jLenSlider = new javax.swing.JSlider();
        jLenLabel = new javax.swing.JLabel();
        jAlfaSlider = new javax.swing.JSlider();
        jAlfaLabel = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLenSlider.setMinorTickSpacing(10);
        jLenSlider.setPaintLabels(true);
        jLenSlider.setPaintTicks(true);
        jLenSlider.setToolTipText("");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${jointLenght}"), jLenSlider, org.jdesktop.beansbinding.BeanProperty.create("value"));
        binding.setSourceNullValue(0);
        binding.setSourceUnreadableValue(2);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jLenSlider, org.jdesktop.beansbinding.ELProperty.create("Length = ${value/10}"), jLenLabel, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jAlfaSlider.setMaximum(90);
        jAlfaSlider.setMinimum(-90);
        jAlfaSlider.setMinorTickSpacing(10);
        jAlfaSlider.setPaintLabels(true);
        jAlfaSlider.setPaintTicks(true);
        jAlfaSlider.setToolTipText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${jointAlfa}"), jAlfaSlider, org.jdesktop.beansbinding.BeanProperty.create("value"));
        binding.setSourceNullValue(0);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jAlfaSlider, org.jdesktop.beansbinding.ELProperty.create("Alfa = ${value}"), jAlfaLabel, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLenLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLenSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jAlfaLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jAlfaSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLenLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLenSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jAlfaLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jAlfaSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jAlfaLabel;
    private javax.swing.JSlider jAlfaSlider;
    private javax.swing.JLabel jLenLabel;
    private javax.swing.JSlider jLenSlider;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
